//////////////////////////////////////////////////////////////////////////////////////////////////////////// // // //---------------------------- Ebrahim Foulaadvand, 11 July 2013 ----------------- // // // // The routine "Dalembert" solves the 1D classical wave equation using centred time centered space // // // CTCS (midpoint leapfrog) scheme. Periodic boundary condition is used. The system length L and the // // wave velocity c are set to one. Initial wave shape is cosine-modulated Gaussian pulse. // // // // // // // //////////////////////////////////////////////////////////////////////////////////////////////////////////// #include #include #include #include #include #include #include #include #include #include using namespace std; main() { double tau=0.004,h,L=1,c=1,a,sigma=0.05,lambda=0.2,k=2*M_PI/lambda,x; int N=200,i,n,T=1000; ofstream file0 ("initial profile n=0.plt"); //output file for the profile at timestep n=0. ofstream file1 ("profile FTCS n=40.plt"); //output file for the profile at timestep n=100. ofstream file2 ("profile FTCS n=50.plt"); //output file for the profile at timestep n=500. ofstream file3 ("profile FTCS n=60.plt"); //output file for the profile at timestep n=500. vector u(N+1,0),unew(N+1,0),uold(N+1,0),f(N+1,0),g(N+1,0); // Arrays "u", "unew" and "uold" store the current, updated and previous values // of the scaler function u(x,t) at grid points. Array "g" stores the second initial conditions: // du(x,0)/dt=g(x). Here we take g(x)=0 for simplicity. h=L/N; cout<<"h= "<